package com.dps.omc.schedule;

import com.dps.omc.model.Task;
import com.dps.omc.model.User;
import com.dps.omc.service.ITaskService;
import com.dps.omc.task.message.EnumTaskState;
import com.dps.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * Created by DXH on 2016/5/11.
 */
@Service
public class UpdateFailTask extends BaseTask{
    @Autowired
    private ITaskService taskService;
    public void execute() throws Exception {
        logInfo("UpdateFailTask任务开始");

//        Date date = DateUtils.getSpecifiedDayBefore(DateUtils.getNowDate(),1);
        //System.out.printf(DateUtils.formatDatetime(date));
        //EnumTaskState state= EnumTaskState.LOADING;
        Date queryDate = DateUtils.desHour(DateUtils.now(),12);//获取十二个小时
        List<Task> tasks = taskService.queryByStatusAndStartDate(EnumTaskState.LOADING,queryDate);
        User user = new User();
        user.setRealName("SYS");
        for (Task task:tasks){
            task.setStatus(EnumTaskState.FAIL);
            taskService.update(task,user);
        }
        logInfo("UpdateFailTask任务结束");
    }

}
